package com.zjj.lbw.ai.old.interviiew;

import org.springframework.ai.autoconfigure.ollama.OllamaEmbeddingProperties;
import org.springframework.ai.embedding.EmbeddingClient;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.vectorstore.RedisVectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 注入redis向量存储，这里和 rag包中只打开一个
 */
@Configuration
public class InterviewBeanConfiguration {
    @Bean
    public RedisVectorStore vectorStore(EmbeddingClient embeddingClient) {
        RedisVectorStore.RedisVectorStoreConfig config = RedisVectorStore.RedisVectorStoreConfig.builder()
                .withURI("redis://localhost:6379")
                .withIndexName("interview-assistant-index")
                .withMetadataFields(
                        RedisVectorStore.MetadataField.text("filename"),
                        RedisVectorStore.MetadataField.text("question"))
                .build();
        return new RedisVectorStore(config, embeddingClient);
    }

    @Bean
    public ZjjOllamaEmbeddingClient ollamaEmbeddingClient(OllamaApi ollamaApi, OllamaEmbeddingProperties properties) {
        ZjjOllamaEmbeddingClient embedddingClient = new ZjjOllamaEmbeddingClient(ollamaApi);
        embedddingClient.withModel("nomic-embed-text:v1.5");
        return embedddingClient;
    }
}
